#include <iostream>
#include <vector>
#include <stdexcept> // 包含标准异常类

void test_throw_exception(int cmd)
{
    if (cmd == 1)
    {
        throw std::runtime_error("11 runtime_error"); // 抛出一个std::runtime_error异常
    }
    else if (cmd == 2)
    {
        throw std::invalid_argument("22 invalid_argument"); // 抛出一个std::invalid_argument异常
    }
    else if (cmd == 3)
    {
        throw std::out_of_range("33 out_of_range"); // 抛出一个std::out_of_range异常
    }
    else if (cmd == 4)
    {
        throw std::logic_error("44 logic_error"); // 抛出一个std::logic_error异常
    }
    else if (cmd == 5)
    {
        throw std::overflow_error("55 overflow_error"); // 抛出一个溢出异常
    }
}

int main()
{
    std::vector<int> cmd = {1, 2, 3, 4, 5};

    for (int i = 0; i < cmd.size(); i++)
    {
        try
        {
            test_throw_exception(cmd[i]);
        }
        catch (const std::exception &e)
        {
            std::cerr << "Caught exception: " << e.what() << '\n';
        }
        catch (...) // 捕获其他所有未处理的异常
        {
            std::cerr << "An unknown exception occurred.\n";
        }
    }

    return 0;
}